package party.lovey.remote.utils;

import org.junit.Test;
import party.lovey.remote.amq.Receiver;
import party.lovey.remote.amq.Sender;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import static org.junit.Assert.assertTrue;

public class Main {

    public static void main(String[] args) throws IOException {

        Map map=new HashMap<>();
        map.put("point",new Point());
        Set set = map.entrySet();
        Object next = set.iterator().next();
        next.toString();

    }

    @Test
    public void testSender() {
        int i = 10;
        while (i-- > 0) {
            BufferedImage screenImage = RobotUtil.getScreenImage();
            Sender.sendBinaryMessage(Consts.DEFEALT_QUEUE_NAME, ImageUtil.toBytes(screenImage));
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    @Test
    public void testReceiver() {

        byte[] bytes = Receiver.receiveBinaryMessage(Consts.DEFEALT_QUEUE_NAME);
        BufferedImage bufferedImage = ImageUtil.fromBytes(bytes);
        bufferedImage = ImageUtil.revertImage(bufferedImage);
        boolean result = ImageUtil.saveToPath(bufferedImage, Consts.DESKTOP_PATH);
        assertTrue(result);
    }

    @Test
    public void testImageRevert() {
        try {
            BufferedImage bufferedImage = ImageIO.read(new File(Consts.DESKTOP_PATH + "123.jpg"));
            bufferedImage = ImageUtil.revertImage2(bufferedImage);
            ImageUtil.saveToPath(bufferedImage, Consts.DESKTOP_PATH);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
